package com.example.xn.snakegame;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

/**
 * Created by xn on 17-3-20.
 */

public class SpashActivity extends Activity {
    boolean ischoose;
    String items[]=new String[]{"30秒吃掉8个","60秒吃掉18个","90秒吃掉25个"};
    Button btn_startgame;
    int item=0;
    Handler handler=new Handler(){
        @Override
        public void handleMessage(Message msg) {
            Intent intent=new Intent(SpashActivity.this,MainActivity.class);
            startActivity(intent);
            finish();
            super.handleMessage(msg);
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.spash_layout);
        btn_startgame= (Button) findViewById(R.id.btn_startgame);
        btn_startgame.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ischoose=false;
                AlertDialog.Builder builder=new AlertDialog.Builder(SpashActivity.this);
                builder.setTitle("请选择时间");
                builder.setSingleChoiceItems(items, 0, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        ischoose=true;
                    item=which;

                    }
                });
                  builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                      @Override
                      public void onClick(DialogInterface dialog, int which) {
                          //Toast.makeText(SpashActivity.this,""+items[item],Toast.LENGTH_SHORT).show();
                          Intent intent=new Intent(SpashActivity.this,MainActivity.class);
                          if(!ischoose)
                              item=0;
                          if(item==0)
                          {
                              intent.putExtra("item",30);
                          }
                          else if(item==1)
                          {
                            intent.putExtra("item",60);
                          }else
                          {
                              intent.putExtra("item",90);
                          }
                          startActivity(intent);
                      }
                  });
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                builder.show();
            }
        });
    }
}
